package com.lc.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @description:实现退出功能，清空session
 * @author: ManolinCoder
 * @time: 2021/8/22
 */
@WebServlet("/loginout")
public class OutServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //清除session
        req.getSession().invalidate();
        //跳转到登录页面
//        resp.sendRedirect("login.jsp");由于该页面使用了frame框架，所以这种方式只能局部跳出
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter writer = resp.getWriter();
        //采用js中的top.location.href=页面地址 的方式可以实现整个页面的跳转
        writer.println("<script>top.location.href='login.jsp';</script>");
    }
}
